package com.bjtime.hprinter.Fragments.designer

import android.content.DialogInterface
import android.os.Bundle
import android.support.v4.app.Fragment
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.LinearLayout
import com.bjtime.designer.attributes.ViewAttr
import com.bjtime.designer.widget.BaseLabelView
import com.bjtime.hprinter.R

/**
 * 元素page
 */

class Eles : Fragment , View.OnClickListener{

    constructor()

    private var mView: View? = null


    companion object {
        fun newInstance(): Eles {
            return Eles()
        }
    }





    override fun onCreateView(
        inflater: LayoutInflater,
        container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View? {
        mView = LayoutInflater.from(context).inflate(R.layout.viewpager_layout_eles, null)
        mView!!.findViewById<LinearLayout>(R.id.desing_ele_text).setOnClickListener(this)
        mView!!.findViewById<LinearLayout>(R.id.desing_ele_qcode).setOnClickListener(this)
        mView!!.findViewById<LinearLayout>(R.id.desing_ele_bcode).setOnClickListener(this)
        mView!!.findViewById<LinearLayout>(R.id.desing_ele_line).setOnClickListener(this)
        mView!!.findViewById<LinearLayout>(R.id.desing_ele_data).setOnClickListener(this)
        mView!!.findViewById<LinearLayout>(R.id.desing_ele_rect).setOnClickListener(this)
        mView!!.findViewById<LinearLayout>(R.id.desing_ele_image).setOnClickListener(this)
        mView!!.findViewById<LinearLayout>(R.id.desing_ele_reverse_layout).setOnClickListener(this)
        return mView
    }


    public interface OnEleClickListener {
        fun onClickEle (t : ViewAttr.VIEW_TYPE)
    }
    private var onEleSelect : OnEleClickListener? = null
    fun setOnEleClickListener (l:OnEleClickListener) {
        onEleSelect = l
    }

    override fun onClick(v: View?) {
        if (onEleSelect != null)
            when (v!!.id) {
                R.id.desing_ele_text -> onEleSelect!!.onClickEle(ViewAttr.VIEW_TYPE.TEXT)
                R.id.desing_ele_qcode -> onEleSelect!!.onClickEle(ViewAttr.VIEW_TYPE.QRCODE)
                R.id.desing_ele_bcode -> onEleSelect!!.onClickEle(ViewAttr.VIEW_TYPE.BARCODE)
                R.id.desing_ele_line -> onEleSelect!!.onClickEle(ViewAttr.VIEW_TYPE.LINE)
                R.id.desing_ele_data -> {
                    var ad = android.app.AlertDialog.Builder (context).create ()
                    ad.setTitle("信息！")
                    ad.setMessage("时间文本标签,也就是文本标签,内容自动格式化日期时间\n暂未开放.")
                    ad.setButton("懂了", DialogInterface.OnClickListener({ a, o ->
                        a.dismiss()
                    }))
                    ad.show()
                }
                R.id.desing_ele_rect -> {
                    var ad = android.app.AlertDialog.Builder (context).create ()
                    ad.setTitle("信息！")
                    ad.setMessage("自定义图形区域,支持圆形,圆角矩形,三角形等,目前未开放.")
                    ad.setButton("懂了", DialogInterface.OnClickListener({ a, o ->
                        a.dismiss()
                    }))
                    ad.show()
                }
                R.id.desing_ele_image -> onEleSelect!!.onClickEle(ViewAttr.VIEW_TYPE.IMAGE)
                R.id.desing_ele_reverse_layout -> {
                    var ad = android.app.AlertDialog.Builder (context).create ()
                    ad.setTitle("信息！")
                    ad.setMessage("此标签为布局器,可以向本布局器内添加一个非反向布局的元素,在此布局内的元素,在实际打印时,将会以反相的方式进行打印.\n本布局器目前还未完善.........")
                    ad.setButton("懂了", DialogInterface.OnClickListener({ a, o ->
                        a.dismiss()
                    }))
                    ad.show()
                }
            }


    }
}